﻿using MongoDB.Driver;
using Sustainalytics.ClientDW.Synchronization.SyncESGData.AbstractClassesAndInterfaces;
using Sustainalytics.Synchronization.Interface;
using Sustainalytics.ESG.Entities;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Sustainalytics.ClientDW.Synchronization.SyncESGData.SubPeerGroupKeyIssueLogic
{
    public class SubPeerGroupKeyIssueCommand : SyncEsgCommand<SubPeerGroupKeyEsgIssue>
    {
        private readonly IMongoCollection<SubPeerGroupKeyEsgIssue> subPeerGroupKeyEsgIssueCollection;

        public SubPeerGroupKeyIssueCommand(IMongoCollection<SubPeerGroupKeyEsgIssue> subPeerGroupKeyEsgIssueCollection, ILogger logger) : base(logger)
        {
            this.subPeerGroupKeyEsgIssueCollection = subPeerGroupKeyEsgIssueCollection;
        }

        protected override async Task<DeleteResult> DeleteAssociatedRecordsAsync(IEnumerable<Guid> companiesIds = null, Guid? additionalDiscriminator = null)
        {
            return await subPeerGroupKeyEsgIssueCollection.DeleteManyAsync(Builders<SubPeerGroupKeyEsgIssue>.Filter.Empty).ConfigureAwait(false);
        }

        protected override async Task InsertRecordsAsync(IEnumerable<SubPeerGroupKeyEsgIssue> entities)
        {
            await subPeerGroupKeyEsgIssueCollection.InsertManyAsync(entities).ConfigureAwait(false);
        }
    }
}
